from LeetCoder import *


class Solution:
    def runeReserve(self, runes: List[int]) -> int:
        runes.sort()
        n = len(runes)
        dp = [1] * n
        for i in range(1, n):
            l = bisect.bisect_right(runes, runes[i], hi=i) - 1
            if runes[l] == runes[i] or runes[l] + 1 == runes[i]:
                dp[i] = dp[l] + 1
        return max(dp)


s = Solution()
print(s.runeReserve([1, 3, 5, 4, 1, 7]))
print(s.runeReserve([1, 1, 3, 3, 2, 4]))
